package com.cyb.beta.service;

import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
 * 定时执行线程池
 * @author chenyongbo
 * @date 2016/4/13.
 */
public class SafeScheduledExecutorService{
    private final ScheduledExecutorService executorService;

    public SafeScheduledExecutorService(ScheduledExecutorService executorService){
        this.executorService = executorService;
    }

    public ScheduledExecutorService getService(){
        return executorService;
    }

    public ScheduledFuture<?> schedule(ScheduleRunnable runnable, long delay,
            TimeUnit timeUnit){
        return executorService.schedule(runnable, delay, timeUnit);
    }

    public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay,
            TimeUnit timeUnit){
        return executorService.schedule(callable, delay, timeUnit);
    }

    public ScheduledFuture<?> scheduleAtFixedRate(ScheduleRunnable runnable,
            long initDelay, long delay, TimeUnit timeUnit){
        return executorService.scheduleAtFixedRate(runnable, initDelay, delay,
                timeUnit);
    }

    public ScheduledFuture<?> scheduleWithFixedDelay(ScheduleRunnable runnable,
            long initDelay, long delay, TimeUnit timeUnit){
        return executorService.scheduleWithFixedDelay(runnable, initDelay,
                delay, timeUnit);
    }
}
